package com.mg.framework.kernel;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

public class ScreenFactory {

	private static Map<String, Screen> screens = null;
	private static MV mv = null;
	private static int screenWidth = 0;
	private static int screenHeight = 0;

	static void initScreenFactory(int screenWidth, int screenHeight) {
		ScreenFactory.screens = new HashMap<String, Screen>();
		ScreenFactory.screenWidth = screenWidth;
		ScreenFactory.screenHeight = screenHeight;
	}

	static void setMV(MV mv) {
		ScreenFactory.mv = mv;
	}

	public static Screen newScreen(String screenName, Class<?> screenClass) {
		Screen newScreen = null;
		try {
			newScreen = (Screen) screenClass.getConstructor(int.class,
					int.class).newInstance(screenWidth, screenHeight);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}
		screens.put(screenName, newScreen);
		return newScreen;
	}

	public static void changeScreen(String screenName) {
		mv.setScreen(screens.get(screenName));
	}
}